﻿using System;
using System.Data;
using System.Text;
using System.Data.SQLite;//Please add references
namespace Bussiness
{
    /// <summary>
    /// 类ReleatedItem。
    /// </summary>
    [Serializable]
    public partial class ReleatedItem
    {
        public ReleatedItem()
        { }
        #region Model
        private int _id;
        private string _storeid;
        private string _link;
        private string _img;
        private string _text;
        /// <summary>
        /// 
        /// </summary>
        public int id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string storeid
        {
            set { _storeid = value; }
            get { return _storeid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string link
        {
            set { _link = value; }
            get { return _link; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string img
        {
            set { _img = value; }
            get { return _img; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string text
        {
            set { _text = value; }
            get { return _text; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ReleatedItem(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,storeid,link,img,text ");
            strSql.Append(" FROM [ReleatedItem] ");
            strSql.Append(" where id=@id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)};
            parameters[0].Value = id;

            DataSet ds = SqliteHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    this.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["storeid"] != null && ds.Tables[0].Rows[0]["storeid"].ToString() != "")
                {
                    this.storeid = ds.Tables[0].Rows[0]["storeid"].ToString();
                }
                if (ds.Tables[0].Rows[0]["link"] != null && ds.Tables[0].Rows[0]["link"].ToString() != "")
                {
                    this.link = ds.Tables[0].Rows[0]["link"].ToString();
                }
                if (ds.Tables[0].Rows[0]["img"] != null && ds.Tables[0].Rows[0]["img"].ToString() != "")
                {
                    this.img = ds.Tables[0].Rows[0]["img"].ToString();
                }
                if (ds.Tables[0].Rows[0]["text"] != null && ds.Tables[0].Rows[0]["text"].ToString() != "")
                {
                    this.text = ds.Tables[0].Rows[0]["text"].ToString();
                }
            }
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [ReleatedItem]");
            strSql.Append(" where id=@id ");

            SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)};
            parameters[0].Value = id;

            return SqliteHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [ReleatedItem] (");
            strSql.Append("storeid,link,img,text)");
            strSql.Append(" values (");
            strSql.Append("@storeid,@link,@img,@text)");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@storeid", DbType.String),
					new SQLiteParameter("@link", DbType.String),
					new SQLiteParameter("@img", DbType.String),
					new SQLiteParameter("@text", DbType.String)};
            parameters[0].Value = storeid;
            parameters[1].Value = link;
            parameters[2].Value = img;
            parameters[3].Value = text;

            return SqliteHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [ReleatedItem] set ");
            strSql.Append("storeid=@storeid,");
            strSql.Append("link=@link,");
            strSql.Append("img=@img,");
            strSql.Append("text=@text");
            strSql.Append(" where id=@id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@storeid", DbType.String),
					new SQLiteParameter("@link", DbType.String),
					new SQLiteParameter("@img", DbType.String),
					new SQLiteParameter("@text", DbType.String),
					new SQLiteParameter("@id", DbType.Int32,8)};
            parameters[0].Value = storeid;
            parameters[1].Value = link;
            parameters[2].Value = img;
            parameters[3].Value = text;
            parameters[4].Value = id;

            int rows = SqliteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [ReleatedItem] ");
            strSql.Append(" where id=@id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)};
            parameters[0].Value = id;

            int rows = SqliteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,storeid,link,img,text ");
            strSql.Append(" FROM [ReleatedItem] ");
            strSql.Append(" where id=@id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@id", DbType.Int32,4)};
            parameters[0].Value = id;

            DataSet ds = SqliteHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    this.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["storeid"] != null && ds.Tables[0].Rows[0]["storeid"].ToString() != "")
                {
                    this.storeid = ds.Tables[0].Rows[0]["storeid"].ToString();
                }
                if (ds.Tables[0].Rows[0]["link"] != null && ds.Tables[0].Rows[0]["link"].ToString() != "")
                {
                    this.link = ds.Tables[0].Rows[0]["link"].ToString();
                }
                if (ds.Tables[0].Rows[0]["img"] != null && ds.Tables[0].Rows[0]["img"].ToString() != "")
                {
                    this.img = ds.Tables[0].Rows[0]["img"].ToString();
                }
                if (ds.Tables[0].Rows[0]["text"] != null && ds.Tables[0].Rows[0]["text"].ToString() != "")
                {
                    this.text = ds.Tables[0].Rows[0]["text"].ToString();
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [ReleatedItem] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SqliteHelper.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

